<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>角色分配</title>
    <link href="../layui-v2.5.6/css/layui.css" rel="stylesheet">
</head>
<body>
<form action="" class="layui-form layui-form-pane" id="saveForm" lay-filter="saveForm" method="post"
      style="margin: 1%;">
    <input id="id" name="id" style="display: none;" value="${user.id!}"/>
    <div class="layui-form-item">
        <label class="layui-form-label" title="角色">角色</label>
        <div class="layui-input-block">
            <#list roleList as role>
            <input lay-skin="primary" name="roleList[${role_index}].id" title="${role.roleName}" type="checkbox"
                   value="${role.id}"
            <#if user.roleList?? && user.roleList?seq_contains(role)> checked <#else> unchecked </#if> >
    </#list>
    </div>
    </div>
    <div class="layui-form-item" style="text-align: center;">
        <div class="layui-inline">
            <button class="layui-btn" lay-filter="save" lay-submit="" style="width: 200px;">保存</button>
        </div>
    </div>
</form>
</body>
<script src="../jquery/jquery-3.4.1.js"></script>
<script src="../layui-v2.5.6/layui.js"></script>
<script type="text/javascript">
    $(function () {
        layui.use(['form'], function () {
            var form = layui.form;
            var layer = layui.layer;
            form.on('submit(save)', function (data) {
                $.ajax({
                    type: "POST",
                    data:data.field,
                    url: "save",
                    success: function (data) {
                        if (data.status == 0) {
                            layer.alert(data.message, function () {
                                layer.closeAll();
                                var index = parent.layer.getFrameIndex(window.name);
                                parent.layer.close(index);
                            });
                        } else {
                            layer.alert(data.message);
                        }
                    },
                    error: function (data) {
                        layer.alert("操作请求错误，请您稍后再试");
                    }
                });
                return false;
            });
        });
    })
</script>
</html>